# -*- coding: utf-8 -*-


import requests
from bs4 import BeautifulSoup

user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5)'
headers = {'User-Agent': user_agent}
session = requests.session()

def getAndSaveUrl( url):
    print(url)
    page = session.get(url, headers=headers)
    soup = BeautifulSoup(page.text, 'lxml')
    contents = soup.findAll('div', id='contentleft')
    for child in contents:
        item = child.findAll('h2')
        for hValue in item:
            aValue = hValue.find('a')
            title = aValue.string
            url = aValue['href']
            print(title)
            f = open('D:/网址.txt', 'a')
            f.write('\n' + url)

# sum大小 请根据网站最新页数调整
sum = 181
index =1
while index <= 181:
    url="http://www.mou5.com/page/%d"%(index)
    getAndSaveUrl(url)
    index = index + 1








